package com.studyroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studyroom.entity.Snack;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SnackMapper extends BaseMapper<Snack> {
    
    @Select("SELECT * FROM snacks " +
           "WHERE (#{name} IS NULL OR name LIKE CONCAT('%', #{name}, '%')) " +
           "AND (#{minPrice} IS NULL OR price >= #{minPrice}) " +
           "AND (#{maxPrice} IS NULL OR price <= #{maxPrice}) " +
           "AND (#{minStock} IS NULL OR stock >= #{minStock}) " +
           "AND (#{maxStock} IS NULL OR stock <= #{maxStock}) " +
           "AND (#{status} IS NULL OR status = #{status}) " +
           "ORDER BY created_at DESC")
    Page<Snack> selectSnackPage(Page<Snack> page, 
                               @Param("name") String name,
                               @Param("minPrice") Double minPrice,
                               @Param("maxPrice") Double maxPrice,
                               @Param("minStock") Integer minStock,
                               @Param("maxStock") Integer maxStock,
                               @Param("status") Integer status);
} 